package com.example.myapplication.ui.user;

import android.widget.RadioGroup;

import androidx.fragment.app.Fragment;

import com.example.myapplication.R;
import com.example.myapplication.adapter.MainPagerAdapter;
import com.example.myapplication.databinding.ActivityMainBinding;
import com.example.myapplication.fragment.CircleFragment;
import com.example.myapplication.fragment.CommunicationFragment;
import com.example.myapplication.fragment.MShopListFragment;
import com.example.myapplication.fragment.ShopCarFragment;
import com.example.myapplication.fragment.UserMeFragment;

import java.util.ArrayList;
import java.util.List;

import cn.project.base.baseui.BaseNormalActivity;

public class UserMainActivity extends BaseNormalActivity<ActivityMainBinding>  implements RadioGroup.OnCheckedChangeListener{


    private long clickTime;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
        mBinding.radioGroup.setOnCheckedChangeListener(this);
    }

    @Override
    protected void initData() {
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new MShopListFragment());
        fragments.add(new ShopCarFragment());
        fragments.add(new CircleFragment());
        fragments.add(new CommunicationFragment());
        fragments.add(new UserMeFragment());
        MainPagerAdapter adapter = new MainPagerAdapter(getSupportFragmentManager(), fragments);
        mBinding.mainPager.setOffscreenPageLimit(2);
        mBinding.mainPager.setAdapter(adapter);
    }


    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.tab_home:
                mBinding.mainPager.setCurrentItem(0, true);
                break;
            case R.id.tab_analyse:
                mBinding.mainPager.setCurrentItem(1, true);
                break;
            case R.id.tab_jihua:
                mBinding.mainPager.setCurrentItem(2, true);
                break;
            case R.id.tab_circle:
                mBinding.mainPager.setCurrentItem(3, true);
                break;
            case R.id.tab_me:
                mBinding.mainPager.setCurrentItem(4, true);
                break;
        }
    }

}
